import { defineStore } from "pinia";
import mockApi from "../api/api.js";
export const userStore = defineStore("userStore", {
  state: () => {
    return {
      userInfo: JSON.parse(sessionStorage.getItem('userInfo')),
      riskTypeList: []
    }
  },

  actions: {
    async getMapData() {
      return new Promise((resolve) => {
        if (this.riskTypeList.length > 0) return resolve()
        // mockApi.queryConfigCode({ codeType: 'riskType' }).then(res => {
        let res = {
          "code": 200,
          "msg": "配置信息查询成功",
          "data": [
            {
              "codeType": "riskType",
              "code1": "00",
              "code2": null,
              "codeName": "全选",
              "codeAlias1": null,
              "codeAlias2": null,
              "codeAlias3": null
            },
            {
              "codeType": "riskType",
              "code1": "NT",
              "code2": null,
              "codeName": "护理险",
              "codeAlias1": null,
              "codeAlias2": null,
              "codeAlias3": null
            },
            {
              "codeType": "riskType",
              "code2": null,
              "codeName": "疾病险",
              "code1": "CT",
              "codeAlias1": null,
              "codeAlias2": null,
              "codeAlias3": null
            }
          ]
        }
        if (res.code == 200) {
          res.data.forEach(item => {
            if (item.codeName == '全选') {
              item.codeName = '整体'
              item.code = 'continueRate'
              item.n = res.data.length
            } else if (item.codeName == '护理险') item.n = 1
            else if (item.codeName == '疾病险') item.n = 2
          })
          // this.riskTypeList = res.data.sort((a, b) => a.n - b.n)
          this.riskTypeList = res.data
        }
        // })
        resolve();
      })
    },
    setUserStore(state) {
      this.userInfo = state.userInfo;
    },
  }
});